#include "MsgUtils.h"
//创建消息队列
int getMsgQueue(char *pathName,int processId)
{
    //首先需要创建key值
    key_t key = ftok(pathName,processId);
    if (key == -1)
    {
        perror("create key failed");
        return -1;
    }
    //通过获取到的key值来获取消息队列
    int msgId = msgget(key,IPC_CREAT|0666);
    if (msgId == -1)
    {
        perror("get msgId failed");
        return -1;
    }
    return msgId;
}
//发消息
int sendMsg(int mqId,Message *msg,int msgSize)
{
    int sendflg = msgsnd(mqId,msg,msgSize,0);
    if (sendflg == -1)
    {
        perror("send msg failed");
        return -1;
    }
    return sendflg;
}
//收消息
int recvMsg(int mqId,Message *msg,int msgSize)
{
    int recvflg = msgrcv(mqId,msg,msgSize,0,0); //此时0为阻塞状态
    if (recvflg == -1)
    {
        perror("recv msg failed");
        return -1;
    }
    return recvflg;
}